package com.ruoyi.source.controller;

import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.common.core.web.page.TableSupport;
import com.ruoyi.source.api.domain.SrcCropGrow;
import com.ruoyi.source.service.ISrcCropGrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 农作物生长情况Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/grow")
public class SrcCropGrowController extends BaseController
{
    @Autowired
    private ISrcCropGrowService srcCropGrowService;

    /**
     * 查询农作物生长情况列表
     */
    @RequiresPermissions("source:grow:list")
    @GetMapping("/list")
    public TableDataInfo list(SrcCropGrow srcCropGrow) {
        IPage<SrcCropGrow> iPage = new Page<>();
        iPage.setCurrent(Convert.toInt(ServletUtils.getParameter(TableSupport.PAGE_NUM), 1));
        iPage.setSize(Convert.toInt(ServletUtils.getParameter(TableSupport.PAGE_SIZE), 10));
        IPage<SrcCropGrow> page = srcCropGrowService.selectSrcCropGrowList(iPage,srcCropGrow);
        return getDataTable(page.getRecords(),page.getTotal());
    }

    /**
     * 导出农作物生长情况列表
     */
    @RequiresPermissions("source:grow:export")
    @Log(title = "农作物生长情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrcCropGrow srcCropGrow) {
        IPage<SrcCropGrow> iPage = new Page<>();
        iPage.setCurrent(Convert.toInt(ServletUtils.getParameter(TableSupport.PAGE_NUM), 1));
        iPage.setSize(-1);
        IPage<SrcCropGrow> page = srcCropGrowService.selectSrcCropGrowList(iPage,srcCropGrow);
        ExcelUtil<SrcCropGrow> util = new ExcelUtil<SrcCropGrow>(SrcCropGrow.class);
        util.exportExcel(response, page.getRecords(), "农作物生长情况数据");
    }

    /**
     * 获取农作物生长情况详细信息
     */
    @RequiresPermissions("source:grow:query")
    @GetMapping(value = "/{growId}")
    public AjaxResult getInfo(@PathVariable("growId") Long growId)
    {
        return success(srcCropGrowService.selectSrcCropGrowByGrowId(growId));
    }

    /**
     * 新增农作物生长情况
     */
    @RequiresPermissions("source:grow:add")
    @Log(title = "农作物生长情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrcCropGrow srcCropGrow) {
        return toAjax(srcCropGrowService.insertSrcCropGrow(srcCropGrow));
    }

    /**
     * 修改农作物生长情况
     */
    @RequiresPermissions("source:grow:edit")
    @Log(title = "农作物生长情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrcCropGrow srcCropGrow)
    {
        return toAjax(srcCropGrowService.updateSrcCropGrow(srcCropGrow));
    }

    /**
     * 删除农作物生长情况
     */
    @RequiresPermissions("source:grow:remove")
    @Log(title = "农作物生长情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{growIds}")
    public AjaxResult remove(@PathVariable Long[] growIds)
    {
        return toAjax(srcCropGrowService.deleteSrcCropGrowByGrowIds(growIds));
    }
}
